#include "Renderer_PCH.h"
#include "RConst.h"

/*--------------------------------------------------------------------------*/

RConst::RConst( EConst::Type type, uint count ) :
	m_type(type),
	m_count(count),
	m_data(NULL),
	m_constUpdater(NULL),
	m_constUpdaterArg(0)
{
	switch (type)
	{
	case EConst::Float1:
		{
			m_data = new uchar[count * 4 + 15];
			break;
		}
	case EConst::Int4:
	case EConst::Float4:
		{
			m_data = new uchar[count * 16 + 15];
			break;
		}
	case EConst::Mat4:
		{
			m_data = new uchar[count * 64 + 15];
			break;
		}
	}	

	m_alignedData = (uchar*) ALIGN((uint) m_data, 16);
}

/*--------------------------------------------------------------------------*/

RConst::~RConst()
{
	delete [] m_data;
}

/*--------------------------------------------------------------------------*/

EConst::Type RConst::GetType() const
{
	return m_type;
}

/*--------------------------------------------------------------------------*/

uint RConst::GetTotalSize() const
{
	switch (m_type)
	{
	case EConst::Float1:
		{
			return m_count * 4;
		}
	case EConst::Int4:
	case EConst::Float4:
		{
			return m_count * 16;
		}
	case EConst::Mat4:
		{
			return m_count * 64;
		}
	}

	__Check(false);
	return 0;
}

/*--------------------------------------------------------------------------*/

uint RConst::GetCount() const
{
	return m_count;
}

/*--------------------------------------------------------------------------*/

uchar* RConst::GetPointer() const
{
	return m_alignedData;
}

/*--------------------------------------------------------------------------*/

IConstUpdater* RConst::GetConstUpdater() const
{
	return m_constUpdater;
}

/*--------------------------------------------------------------------------*/

uint RConst::GetConstUpdaterArg() const
{
	return m_constUpdaterArg;
}

/*--------------------------------------------------------------------------*/

void RConst::Update() const
{
	if (m_constUpdater)
	{
		m_constUpdater->UpdateConst(m_constUpdaterArg);
	}
}

/*--------------------------------------------------------------------------*/
